<?php
	if (!current_user_can('manage_options'))
	{
		wp_die('You do not have sufficient permissions to access this page.');
	}
    global $wpdb;
    if($_GET['reply'])
    {
        $email_status = $_GET['reply'];
        $email_id = $_GET['email_id'];
        $ud = "UPDATE {$wpdb->prefix}feedback SET reply='{$email_status}' WHERE feedback_id = {$email_id}";
        $wpdb->get_results($ud);
    }

    $qr = "select * from {$wpdb->prefix}feedback order by time desc";
    $rs = $wpdb->get_results($qr);
?>
<style type="text/css">
    table.ex{border: 1px solid;text-align: left;}
    table.ex tr td{border: 1px solid #BBB;}
    table.ex #site{background: whitesmoke;}
    .em_head{font-weight: bold;}
</style>
      <div class="wrap">
        <?php screen_icon('themes'); ?> <h2>Contacts ( <?php echo count($rs); ?> )</h2>
        <form method="POST" action="">
            <table class="form-table ex" style="text-align: center;">
                <tr valign="top" class="em_head">
                    <td>Reply</td>
                    <td><label>Name</label></td>
                    <td><label>Email</label></td>
                    <td><label>Title</label></td>
                    <td><label>Content</label></td>
                    <td><label>Time (GMT +7)</label></td>
                </tr>
                <?php if(count($rs) > 0): foreach ($rs as $obj): ?>
                <tr>

                    <?php if($obj->reply == '' || $obj->reply != 'yes'): ?>
                    <td>
                        <a title="Mark as replied" href="<?php echo cpx_current_url().'&reply=yes&email_id='.$obj->feedback_id?>">Yes</a>
                    </td>
                    <?php elseif($obj->reply == 'yes'): ?>
                    <td style="background-color: grey">
                        <a style="color: white;" title="Mark as unreply" href="<?php echo cpx_current_url().'&reply=no&email_id='.$obj->feedback_id?>">No</a>
                    <?php endif; ?>
                    </td>
                    <td><?php echo strtoupper($obj->send_by); ?></td>
                    <td><a title="Send email to this contact" href="mailto:<?php echo $obj->send_email; ?>"><?php echo $obj->send_email; ?></a></td>
                    <td><?php echo $obj->title;?></td>
                    <td>
                        <textarea style="width: 100%;height: auto;"><?php echo $obj->send_content; ?></textarea>
                    </td>
                    <td><?php if($obj->TIME != '0000-00-00 00:00:00') echo $obj->TIME; ?></td>
                </tr>
                <?php endforeach; endif;?>
            </table>
        </form>
      </div>